import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class pr3 {
    public static void main(String[] args) {
        int[] arr = {1, 5, 3, 4, 5, 6, 5, 8, 9};
        int target = 5;

        int count=0;
        // 遍历原数组，在新数组中填充目标数字  
        for (int i = 0; i < arr.length; i++) {

                if(arr[i]==5) {
                    count++;
                }
        }
        int[] newArray = new int[count];
        int j=0;

        for (int i = 0; i < arr.length; i++) {

            if (arr[i] == 5) {
                newArray[j] = i;
j++;
            }

        // 打印新数组
    }
        System.out.println(Arrays.toString(newArray));
}
}